import 'package:flutter/material.dart';

class GrewBuilderAnimation extends StatefulWidget {
  @override
  _GrewBuilderAnimationState createState() => _GrewBuilderAnimationState();
}

class _GrewBuilderAnimationState extends State<GrewBuilderAnimation>
    with SingleTickerProviderStateMixin {
  AnimationController _animationController;
  Animation<double> _extrusionAnimation; //挤压动画
  Animation<double> _expansionAnimation; //扩张动画

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    _animationController = AnimationController(
        duration: Duration(milliseconds: 5000), vsync: this);

    _extrusionAnimation = Tween(begin: 300.0, end: 60.0).animate(
        CurvedAnimation(parent: _animationController, curve: Interval(0, .3)));

    _expansionAnimation = Tween(begin: 60.0, end: 1000.0).animate(
        CurvedAnimation(
            parent: _animationController,
            curve: Interval(0.55, .95, curve: Curves.bounceOut)));

    _animationController.forward();
  }

  @override
  void dispose() {
    _animationController.dispose();

    // TODO: implement dispose
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: AnimatedBuilder(
        animation: _animationController,
        builder: (context, child) {
          print("控制器变化---:${_animationController.value}");
          print("动画变化=====:${_extrusionAnimation.value}");
          return Center(
            child: Container(
              width: _expansionAnimation.value == 60
                  ? _extrusionAnimation.value
                  : _expansionAnimation.value,
              height: _expansionAnimation.value == 60
                  ? 60.0
                  : _expansionAnimation.value,
              decoration: BoxDecoration(
                color: Colors.deepOrangeAccent,
                borderRadius: BorderRadius.circular(30.0),
              ),
              child: Center(
                child: _extrusionAnimation.value > 65
                    ? Text(
                        "GO",
                        style: TextStyle(color: Colors.white, fontSize: 20),
                      )
                    : _expansionAnimation.value < 300
                        ? CircularProgressIndicator(
                            strokeWidth: 2.0,
                            valueColor: AlwaysStoppedAnimation<Color>(
                              Colors.white,
                            ),
                          )
                        : null,
              ),
            ),
          );
        },
      ),
    );
  }
}
